/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package XML;

/**
 *
 * @author waelelkholy
 */
// Fig. D.1 : Transform.java
 // Performs XSL Transformations.

//Java core libraries
 import java.io.*;
 import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

// Java standard extensions
import javax.xml.parsers.*;
 import javax.xml.transform.*;
 import javax.xml.transform.dom.*;
 import javax.xml.transform.stream.*;

 // third-party libraries
 import org.w3c.dom.*;
 import org.xml.sax.SAXException;

 public class Transform {

 public void Transform(File xmlfile,File xsltfile,File htmloutput)
 {
    
 // factory for creating DocumentBuilders
 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();

 // factory for creating Transformers
 TransformerFactory transformerFactory = TransformerFactory.newInstance();

 DocumentBuilder builder = null;
         try {
             builder = builderFactory.newDocumentBuilder();
         } catch (ParserConfigurationException ex) {
             Logger.getLogger(Transform.class.getName()).log(Level.SEVERE, null, ex);
         }

 Document document = null;
         try {
             document = builder.parse(xmlfile);
         } catch (SAXException ex) {
             Logger.getLogger(Transform.class.getName()).log(Level.SEVERE, null, ex);
         } catch (IOException ex) {
             Logger.getLogger(Transform.class.getName()).log(Level.SEVERE, null, ex);
         }

 // create DOMSource for source XML document
 Source xmlSource = new DOMSource( document );

 // create StreamSource for XSLT document
 Source xslSource = new StreamSource(xsltfile);

 // create StreamResult for transformation result
 StreamResult result = new StreamResult(htmloutput);

 // create Transformer for XSL transformation
 Transformer transformer = null;
         try {
             transformer = transformerFactory.newTransformer( xslSource );
         } catch (TransformerConfigurationException ex) {
             Logger.getLogger(Transform.class.getName()).log(Level.SEVERE, null, ex);
         }
         try {
             // transform and deliver content to client
             transformer.transform( xmlSource, result );
         } catch (TransformerException ex) {
             Logger.getLogger(Transform.class.getName()).log(Level.SEVERE, null, ex);
         }

 }
     
 // execute application
public static void main( String args[] ) throws Exception
 {

     Transform tr=new Transform();
    // tr.Transform(new File("C:/Users/waelelkholy/Desktop/life maker/GHGH.XML"),new File("C:/Users/waelelkholy/Desktop/life maker/parsing.xsl"));   
// // factory for creating DocumentBuilders
// DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
//
// // factory for creating Transformers
// TransformerFactory transformerFactory = TransformerFactory.newInstance();
//
// DocumentBuilder builder = builderFactory.newDocumentBuilder();
//
// Document document = builder.parse("new_one.xml");
//
// // create DOMSource for source XML document
// Source xmlSource = new DOMSource( document );
//
// // create StreamSource for XSLT document
// Source xslSource = new StreamSource("F:/java/xml/labs/lab2/DOM1/src/xml_xslt_transformation/parsing.xsl");
//
// // create StreamResult for transformation result
// StreamResult result = new StreamResult(new File("F:/java/xml/labs/lab2/DOM1/src/xml_xslt_transformation/wael.xml"));
//
// // create Transformer for XSL transformation
// Transformer transformer = transformerFactory.newTransformer( xslSource );
//
// // transform and deliver content to client
// transformer.transform( xmlSource, result );

 }
 }
